package cn.foolishbird.crow.step;

import org.apache.commons.collections4.CollectionUtils;

import java.util.Collection;
import java.util.Objects;
import java.util.function.Consumer;

/**
 * @author foolish-bird
 */
@Deprecated
public class StepDispose<E> {

    private StepRead<E> stepRead;

    public StepDispose(StepRead<E> stepRead) {
        this.stepRead = stepRead;
    }

    /**
     * 分步处理
     */
    public void stepDispose(Consumer<E> consumer) {
        if (Objects.isNull(stepRead)) {
            throw new RuntimeException("步进读取器不能为空");
        }

        Collection<E> collection = stepRead.next();
        while (CollectionUtils.isNotEmpty(collection)) {
            collection.forEach(consumer::accept);
            collection = stepRead.next();
        }
    }

    public StepRead<E> getStepRead() {
        return stepRead;
    }

    public void setStepRead(StepRead<E> stepRead) {
        this.stepRead = stepRead;
    }
}
